package com.example.mac.yuejian14.model;

import java.util.List;

import com.example.mac.yuejian14.listener.RetrofitListener1;
import com.example.mac.yuejian14.bean.ActivityBean;
import com.example.mac.yuejian14.bean.ConsultBean;
import com.example.mac.yuejian14.bean.TeacherBean;
import com.example.mac.yuejian14.service.TeacherService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2017/10/25.
 */

public class TeacherModel {
    private Retrofit retrofit;

    public TeacherModel(){
        //创建实例
        retrofit = new Retrofit.Builder()
                .baseUrl("http://10.0.2.2/neu12_yuejian/index.php/Api/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    //大师列表
    public Call<List<TeacherBean>> getTeacherList(){
        TeacherService teacherService= retrofit.create(TeacherService.class);
        return teacherService.getTeacherList();
    }
    //添加咨询信息
    public Call<ConsultBean> addconsult (int uid, String co_intro){
        TeacherService teacherService = retrofit.create(TeacherService.class);
        return teacherService.addconsult(uid,co_intro);
    }

    //获取活动详情
    public void getTeacherById(String teachid, final RetrofitListener1 listener){
        TeacherService teacherService = retrofit.create(TeacherService.class);
        Call call = teacherService.getTeacherById(teachid);
        Callback<TeacherBean> callback = new Callback<TeacherBean>() {
            @Override
            public void onResponse(Call<TeacherBean> call, Response<TeacherBean> response) {
                TeacherBean getTeacherById = response.body();
                listener.onSuccess(getTeacherById,1);
            }
            @Override
            public void onFailure(Call<TeacherBean> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);

    }





}
